package com.heima.behavior.service.impl;


import com.heima.behavior.dtos.UnLikesBehaviorDto;
import com.heima.behavior.pojos.ApUnlikesBehavior;
import com.heima.behavior.service.UnLikesBehaviorService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.ApUser;
import com.heima.utils.thread.ApThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Service
public class UnLikesBehaviorImpl  implements UnLikesBehaviorService {

    @Autowired
    private MongoTemplate mongoTemplate;
    /**
     * 不喜欢的代码
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult unlike(UnLikesBehaviorDto dto) {
        //1.参数判断
        if (dto == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //2.获取用户id
        ApUser apUser = ApThreadLocal.getApUser();
        if (apUser == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        if (apUser.getId() == 0) {
            return ResponseResult.okResult(405, "游客身份禁止，需进行登录");
        }
        //定义一个dakey
        String unlikeKey = "USER_UNLIKES_" + dto.getArticleId();
        /**
         *   3.判断当前用户是否点赞过该文章
         * 0 不喜欢
         * 1 取消不喜欢
         */

            Query query =Query.query(
                    Criteria.where("userId").is(apUser.getId()).and("unlike").is(dto.getArticleId())
            );


        return null;
    }
}
